package com.soikc.kuaidiE.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.soikc.kuaidiE.util.DateFormatUtil;
import com.soikc.kuaidiE.util.ResultSetUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

public class KuaiDi {
    private int id;
    private String single_number;//快递单号
    private String user_name;
    private String phone;
    private String company;
    private String Pickup_code;//取件码
    private Date Deposit_time;
    private Date take_out_time;
    private int status;
    private String Depositor_phone;

    public KuaiDi(){
    }

    /**
     * 使用结果集创建一个对象
     * @param resultSet
     * @return
     */
    public static KuaiDi create(ResultSet resultSet) {
        JSONObject jsonObject = ResultSetUtil.toJsonObject(resultSet);
        return jsonObject.toJavaObject(KuaiDi.class);
    }

    /**
     * 创建一组对象
     * @param resultSet
     * @return
     */
    public static List<KuaiDi> createList(ResultSet resultSet){
        List<KuaiDi> list = new ArrayList();
        try {
            while (resultSet.next()){
                list.add(create(resultSet));
            }
        } catch (SQLException err) {
            err.printStackTrace();
        }
        return list;
    }
    public JSONObject toViveObj(){
        JSONObject d = (JSONObject) JSON.toJSON(this);
        d.put("deposit_time", DateFormatUtil.format(this.Deposit_time));
        d.put("take_out_time", DateFormatUtil.format(this.take_out_time));
        switch (this.status){
            case 0:
                d.put("status", "未取出");
                break;
            case 1:
                d.put("status", "已取出");
                break;
            case 2:
                d.put("status", "已删除");
                break;
        }
        return d;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSingle_number() {
        return single_number;
    }

    public void setSingle_number(String single_number) {
        this.single_number = single_number;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getPickup_code() {
        return Pickup_code;
    }

    public void setPickup_code(String pickup_code) {
        Pickup_code = pickup_code;
    }

    public Date getDeposit_time() {
        return Deposit_time;
    }

    public void setDeposit_time(Date deposit_time) {
        Deposit_time = deposit_time;
    }

    public Date getTake_out_time() {
        return take_out_time;
    }

    public void setTake_out_time(Date take_out_time) {
        this.take_out_time = take_out_time;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getDepositor_phone() {
        return Depositor_phone;
    }

    public void setDepositor_phone(String depositor_phone) {
        Depositor_phone = depositor_phone;
    }
}
